/*
 * Copyright 2004 original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.jbfilter.impl;

import java.util.Collection;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;

import org.jbfilter.bean.FilterComponentBean;
import org.jbfilter.bean.PropertyAccessor;
import org.jbfilter.bean.factory.FilterComponentBeans;
import org.jbfilter.bean.fcomps.delegate.PropertyAccessibleBeanDelegate;
import org.jbfilter.bean.fcomps.multiple.StartEndDateFilterComponentBean;
import org.jbfilter.bean.fcomps.single.DateFilterComponentBean;
import org.jbfilter.core.fcomps.logic.AndFilterComponent;
import org.jbfilter.core.fcomps.single.DateFilterComponent;

class _StartEndDateFilterComponentBeanImpl<E>
	extends
		_StartEndDateFilterComponentImpl<E>
	implements StartEndDateFilterComponentBean<E> {

	private PropertyAccessibleBeanDelegate<E, Date> pabDelegate;
	
	// constructors
	_StartEndDateFilterComponentBeanImpl() {
		super();
		pabDelegate = new PropertyAccessibleBeanDelegate<E, Date>();
		pabDelegate.add(getStartCompTyped());
		pabDelegate.add(getEndCompTyped());
	}
	_StartEndDateFilterComponentBeanImpl(String id) {
		this();
		setId(id);
		setPropertyPath(id);
	}
	_StartEndDateFilterComponentBeanImpl(String id, String propertyPath) {
		this();
		setId(id);
		setPropertyPath(propertyPath);
	}
	_StartEndDateFilterComponentBeanImpl(String id, PropertyAccessor<E, Date> propertyAccessor) {
		this();
		setId(id);
		setPropertyAccessor(propertyAccessor);
	}

	@Override
	public Date getPropertyValue(E bean) {
		return pabDelegate.getPropertyValue(bean);
	}
	@Override
	public void setPropertyAccessor(PropertyAccessor<E, Date> propertyAccessor) {
		pabDelegate.setPropertyAccessor(propertyAccessor);
	}
	@Override
	public String getPropertyPath() {
		return pabDelegate.getPropertyPath();
	}
	@Override
	public void setPropertyPath(String propertyPath) {
		pabDelegate.setPropertyPath(propertyPath);
	}
	private DateFilterComponentBean<E> getStartCompTyped() {
		return (DateFilterComponentBean<E>) getStartComp();
	}
	private DateFilterComponentBean<E> getEndCompTyped() {
		return (DateFilterComponentBean<E>) getEndComp();
	}
	@Override
	public void filterOut(LinkedList<E> coll) {
		getActiveFcTyped().filterOut(coll);
	}
	@Override
	public List<E> filter(Collection<E> toFilter) {
		return getActiveFcTyped().filter(toFilter);
	}
	@Override
	public boolean pass(E bean) {
		return getActiveFcTyped().pass(bean);
	}
	private FilterComponentBean<E> getActiveFcTyped() {
		return (FilterComponentBean<E>)getActiveFc();
	}
	@Override
	protected DateFilterComponent<E> initDateFc() {
		return FilterComponentBeans.newDateFilterComponent();
	}
	@Override
	protected AndFilterComponent<E> initAndFc() {
		return FilterComponentBeans.newAndFilterComponent();
	}
}
